package com.test.springai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/4/25 3:05 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
@RequestMapping("/chat")
public class ChatController {
  private final ChatClient chatClient;

  public ChatController(ChatClient.Builder builder) {
    this.chatClient = builder.build();
  }

  @GetMapping("/call")
  public String call(
      @RequestParam(value = "query", defaultValue = "你好很高兴认识你,能简单介绍一下自己吗?") String query) {
    return chatClient.prompt(query).call().content();
  }

  @GetMapping(value = "/stream", produces = "application/json;charset=UTF-8")
  public Flux<String> stream(
      @RequestParam(value = "query", defaultValue = "你好很高兴认识你,能简单介绍一下自己吗?") String query) {
    return chatClient.prompt(query).stream().content();
  }
}
